package com.xmb.wechat.view.wechat.money;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xmb.wechat.R;
import com.xmb.wechat.R2;
import com.xmb.wechat.base.BaseActivity;
import com.xmb.wechat.bean.WechatContactBean;
import com.xmb.wechat.bean.WechatMsgBean;
import com.xmb.wechat.util.MoneyFormat;
import com.xmb.wechat.util.WechatDateFormat;

import java.text.SimpleDateFormat;

import butterknife.BindView;
import butterknife.OnClick;

public class WechatFundRedPacketDetailActivity extends BaseActivity {

    //通用
    @BindView(R2.id.iv_avatar)
    ImageView    mIvAvatar;
    @BindView(R2.id.tv_avatar)
    TextView     mTvAvatar;
    @BindView(R2.id.tv_remark)
    TextView     mTvRemark;
    @BindView(R2.id.ll_other_send)
    LinearLayout mLlOtherSend;
    @BindView(R2.id.ll_me_send)
    LinearLayout mLlMeSend;

    //别人发的红包
    @BindView(R2.id.tv_other_money)
    TextView  mTvOtherMoney;
    @BindView(R2.id.iv_other_avatar_receiver)
    ImageView mIvOtherAvatarReceiver;
    @BindView(R2.id.tv_other_receiver_name)
    TextView  mTvOtherReceiverName;
    @BindView(R2.id.tv_other_receiver_money)
    TextView  mTvOtherReceiverMoney;
    @BindView(R2.id.tv_other_receiver_time)
    TextView  mTvOtherReceiverTime;

    //我发送的红包
    @BindView(R2.id.tv_me_hint)
    TextView       mTvMeHint;
    @BindView(R2.id.re_me_receiver)
    RelativeLayout mReMeReceiver;
    @BindView(R2.id.iv_me_avatar_receiver)
    ImageView      mIvMeAvatarReceiver;
    @BindView(R2.id.tv_me_receiver_name)
    TextView       mTvMeReceiverName;
    @BindView(R2.id.tv_me_receiver_money)
    TextView       mTvMeReceiverMoney;
    @BindView(R2.id.tv_me_receiver_time)
    TextView       mTvMeReceiverTime;
    @BindView(R2.id.tv_tip_bottom)
    TextView       mTvTipBottom;

    public static void start(Activity act, WechatContactBean sendWechatContactBean, WechatContactBean receiveWechatContactBean, WechatMsgBean wechatMsgBean) {
        Intent it = new Intent(act, WechatFundRedPacketDetailActivity.class);
        it.putExtra("wechatMsgBean", wechatMsgBean);
        it.putExtra("sendContactBean", sendWechatContactBean);
        it.putExtra("receiveContactBean", receiveWechatContactBean);
        act.startActivity(it);
    }

    public WechatFundRedPacketDetailActivity() {
        super(R.layout.activity_fund_red_packet_detail);
        isChangeStatusBarTxtColor = false;
    }

    @SuppressLint({"SimpleDateFormat", "SetTextI18n"})
    @Override
    protected void initView() {
        setStatusBarColor(Color.parseColor("#f35543"));
        setNavigationColor(Color.parseColor("#f7f7f7"));

        WechatMsgBean wechatMsgBean = (WechatMsgBean) getIntent().getSerializableExtra("wechatMsgBean");
        if (wechatMsgBean == null)
            return;
        //通用
        WechatContactBean sendContactBean = (WechatContactBean) getIntent().getSerializableExtra("sendContactBean");
        WechatContactBean.setupAvatarIntoImageView(sendContactBean, mIvAvatar, 12);
        mTvAvatar.setText(getNameWithMe(sendContactBean.getName() )+ "的红包");
        mTvRemark.setText(wechatMsgBean.getMoneyRemark());
        //修改字体
        AssetManager mgr = getAssets();
        Typeface tf = Typeface.createFromAsset(mgr, "fonts/WeChatLqNumber.ttf");
        mTvOtherMoney.setTypeface(tf);

        String format = MoneyFormat.formatMoney(wechatMsgBean.getMoney());
        //选择布局
        if (wechatMsgBean.getMoneySenderID() == -1) {//我发的红包
            mLlMeSend.setVisibility(View.VISIBLE);
            mLlOtherSend.setVisibility(View.GONE);
            if (wechatMsgBean.isReceiveMoney()) {//已领取
                WechatContactBean receiveContactBean = (WechatContactBean) getIntent().getSerializableExtra("receiveContactBean");
                mReMeReceiver.setVisibility(View.VISIBLE);
                mTvTipBottom.setVisibility(View.GONE);
                //showView
                mTvMeHint.setText("1个红包共" + format + "元");
                mTvMeReceiverName.setText(getNameWithMe(receiveContactBean.getName()));
                mTvMeReceiverMoney.setText(format + "元");
                mTvMeReceiverTime.setText(WechatDateFormat.formatRedPacketTime(wechatMsgBean.getReceiveTime(), new SimpleDateFormat("MM月dd日 HH:mm")));
                WechatContactBean.setupAvatarIntoImageView(receiveContactBean, mIvMeAvatarReceiver, 12);
            } else {//未领取
                mReMeReceiver.setVisibility(View.GONE);
                mTvTipBottom.setVisibility(View.VISIBLE);
                //showView
                mTvMeHint.setText("红包金额" + format + "元，等待对方领取");
            }
        } else {
            WechatContactBean receiveContactBean = (WechatContactBean) getIntent().getSerializableExtra("receiveContactBean");
            mLlMeSend.setVisibility(View.GONE);
            mLlOtherSend.setVisibility(View.VISIBLE);
            //showView
            mTvOtherMoney.setText(format);
            mTvOtherReceiverName.setText(getNameWithMe(receiveContactBean.getName()));
            mTvOtherReceiverMoney.setText(format + "元");
            mTvOtherReceiverTime.setText(WechatDateFormat.formatRedPacketTime(wechatMsgBean.getReceiveTime(), new SimpleDateFormat("MM月dd日 HH:mm")));
            WechatContactBean.setupAvatarIntoImageView(receiveContactBean, mIvOtherAvatarReceiver, 12);
        }
    }

    @OnClick(R2.id.iv_back)
    public void onViewClicked() {
        finish();
    }
}
